import { createRouter, createWebHistory } from "vue-router";
import type { Router } from "vue-router";
import { ExperimentOutlined, HomeOutlined } from "@ant-design/icons-vue";
import { setRouterGuards } from "./guards";

const router: Router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      name: "Layouts",
      component: () => import("@/layouts/index.vue"),
      redirect: "/home",
      children: [
        {
          path: "/home",
          name: "home",
          component: () => import("@/views/home/HomePage.vue"),
          meta: {
            title: "首页",
            icon: HomeOutlined,
          },
        },
        {
          path: "/microApp",
          name: "microApp",
          component: () => import("@/views/micro-apps/MicroAppLayout.vue"),
          meta: {
            title: "实验室",
            icon: ExperimentOutlined,
          },
        },
        {
          path: "/microApp/:pathMatch(.*)*",
          name: "microAppWildcard",
          component: () => import("@/views/micro-apps/MicroAppLayout.vue"),
          meta: {
            hidden: true,
          },
        },
      ],
    },
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/infra/Login.vue"),
      meta: {
        title: "登录",
      },
    },
    {
      path: "/register",
      name: "register",
      component: () => import("@/views/infra/register.vue"),
      meta: {
        title: "注册",
      },
    },
    {
      path: "/forgot",
      name: "forgot",
      component: () => import("@/views/infra/forgot.vue"),
      meta: {
        title: "忘记密码",
      },
    },
    {
      path: "/404",
      name: "404",
      component: () => import("@/views/infra/404.vue"),
      meta: {
        title: "404",
      },
    },
    {
      path: "/:pathMatch(.*)*",
      redirect: "/404",
    },
  ],
});

setRouterGuards(router);

export default router;
